package com.yootk.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Map;

@WebServlet("/pages/admin/KickoutServlet")
public class KickoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String path = "/pages/admin/online_user_list.jsp";   // 跳转路径
        String id = req.getParameter("userid"); // 获取用户名
        Map<String, Boolean> map = (Map<String, Boolean>) req.getServletContext().getAttribute("online");
        if (map.containsKey(id)) {  // 指定用户信息存在
            map.put(id, true); // 修改为剔除状态
            req.getServletContext().setAttribute("online", map); // 属性更新
        }
        req.getRequestDispatcher(path).forward(req, resp); // 跳转回用户列表页
    }
}
